package pl.peterjack.model.pdf;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

/**
 * Klasa ufatwiajaca pobieranie danych z plikow XML
 * 
 * @author peterjack
 * 
 */
public class MyXML {

	public static Element getRoot(String fileName) throws Exception {
		File file = new File("WEB-INF/" + fileName);
		SAXBuilder builder = new SAXBuilder();
		Document document = (Document) builder.build(file);
		return document.getRootElement();
	}

	/*
	 * Na podstawie wartosci ustawianej dla firmy
	 */
	public static Element getRootByStylXML(String stylXML) throws Exception {
		String fileName = "";
		if (stylXML != null) {
			fileName = (String) MyXML.class.getDeclaredField(
					"STYL_FAKTURY_" + stylXML).get(null);
		} else {
			fileName = STYL_FAKTURY_DOMYSLNY;
		}
		return getRoot(fileName);
	}

	public static String STYL_FAKTURY_DOMYSLNY = "faktura_domyslny_styl.xml";

	public static List<String> getListaStylow() {
		List<String> lista = new ArrayList<String>();
		lista.add("DOMYSLNY");
		return lista;
	}
}
